package cpp.ece480.compteam;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.CheckBox;
import android.widget.TextView;

public class TableScreen extends Activity {

	public TextView heading;
	public TextView totalPrice;
	
	public TextView custPrice1;
	public TextView custPrice2;
	public TextView custPrice3;
	public TextView custPrice4;
	
	public int tableNumber;
	public int customer1cost;
	public int customer2cost;
	public int customer3cost;
	public int customer4cost;

	public String tablePrice;
	public String customer1price;
	public String customer2price;
	public String customer3price;
	public String customer4price;

	public boolean table1selected; 
	public boolean table2selected; 
	public boolean table3selected; 
	public boolean table4selected; 
	public boolean table5selected; 
	public boolean table6selected;

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.tablescreen);

		table1selected = ((GlobalVariable) this.getApplication()).getTable1();
		table2selected = ((GlobalVariable) this.getApplication()).getTable2();
		table3selected = ((GlobalVariable) this.getApplication()).getTable3();
		table4selected = ((GlobalVariable) this.getApplication()).getTable4();
		table5selected = ((GlobalVariable) this.getApplication()).getTable5();
		table6selected = ((GlobalVariable) this.getApplication()).getTable6();

		if (table1selected) {
			tableNumber = 1;
		} else if (table2selected) {
			tableNumber = 2;
		} else if (table3selected) {
			tableNumber = 3;
		} else if (table4selected) {
			tableNumber = 4;
		} else if (table5selected) {
			tableNumber = 5;
		} else if (table6selected) {
			tableNumber = 6;
		} else {
			tableNumber = 0;
		}

		heading = (TextView) findViewById(R.id.textHeading);
		heading.setText("Table " + tableNumber + " Customers");
		
		custPrice1 = (TextView) findViewById(R.id.custPrice1);
		// TODO customer1costGet total customer price from the database
		custPrice1.setText("$"+ customer1cost);
		
		custPrice2 = (TextView) findViewById(R.id.custPrice2);
		// TODO Get total customer price from the database
		custPrice2.setText("$"+ customer2cost);
		
		custPrice3 = (TextView) findViewById(R.id.custPrice3);
		// TODO Get total customer price from the database
		custPrice3.setText("$"+ customer3cost);
		
		custPrice4 = (TextView) findViewById(R.id.custPrice4);
		// TODO Get total customer price from the database
		custPrice4.setText("$"+ customer4cost);
		
		totalPrice = (TextView) findViewById(R.id.totalPrice);
		// TODO Get total table price from the database
		totalPrice.setText(tablePrice);
	}

	protected void onPause() {
		super.onPause();
	}

	protected void onResume() {
		super.onResume();
	}

	protected void onDestroy() {
		super.onDestroy();
	}

	public void onCheckboxClicked1(View v) {
		if (((CheckBox) v).isChecked()) {
			((GlobalVariable) this.getApplication()).setCustomer1(true);
		} else {
			((GlobalVariable) this.getApplication()).setCustomer1(false);
		}
	}

	public void onCheckboxClicked2(View v) {
		if (((CheckBox) v).isChecked()) {
			((GlobalVariable) this.getApplication()).setCustomer2(true);
		} else {
			((GlobalVariable) this.getApplication()).setCustomer2(false);
		}
	}

	public void onCheckboxClicked3(View v) {
		if (((CheckBox) v).isChecked()) {
			((GlobalVariable) this.getApplication()).setCustomer3(true);
		} else {
			((GlobalVariable) this.getApplication()).setCustomer3(false);
		}
	}

	public void onCheckboxClicked4(View v) {
		if (((CheckBox) v).isChecked()) {
			((GlobalVariable) this.getApplication()).setCustomer4(true);
		} else {
			((GlobalVariable) this.getApplication()).setCustomer4(false);
		}
	}

	public void launchCustomerScreen(View v) {
		Intent intent = new Intent(this, CustomerOrders.class);
		startActivity(intent);
	}

	public void launchCheckoutScreen(View v) {
		Intent intent = new Intent(this, Checkout.class);
		startActivity(intent);
	}
}